package com.zhc.dejingapi.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhc.dejingapi.entity.QingEquipmentEntity;
import com.zhc.dejingapi.entity.SpcEntity;
import com.zhc.dejingapi.mapper.QingEquipmentMapper;
import com.zhc.dejingapi.mapper.SpcMapper;
import com.zhc.dejingapi.service.SpcService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhc
 * @since 2024-07-27
 */
@Service
public class SpcServiceImpl extends ServiceImpl<SpcMapper, SpcEntity> implements SpcService {

    @Resource
    private SpcMapper spcMapper;

    @Resource
    private QingEquipmentMapper qingEquipmentMapper;

    private final RedisTemplate<String,Object> redisTemplate;

    public SpcServiceImpl( @Qualifier("redisTemplateWin")RedisTemplate<String, Object> redisTemplate1) {
        this.redisTemplate = redisTemplate1;
    }


    @Override
    public long getEqRunMoldQty(String eqCode, String reportStartTime, String reportEndTime) {
        QueryWrapper<QingEquipmentEntity> queryWrapper=new QueryWrapper<QingEquipmentEntity>();
        queryWrapper.eq("eqCode", eqCode);
        QingEquipmentEntity qingEquipmentEntity = qingEquipmentMapper.selectOne(queryWrapper);

        QueryWrapper<SpcEntity> query = new QueryWrapper<SpcEntity>();
        query.eq("e_id",qingEquipmentEntity.getMainId()).between("time",reportStartTime,reportEndTime);
        Long l = spcMapper.selectCount(query);
        return l;
    }

    @Override
    public long getEqRunMoldQtyOfTheMonth() {
        QueryWrapper<SpcEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.last("where DATE_FORMAT(time,\"%Y-%m\")=DATE_FORMAT(NOW(),\"%Y-%m\")");
        return spcMapper.selectCount(queryWrapper);
    }


}
